
import database.*;
import database.Restaurant;
import database.user;
import java.awt.CardLayout;
import java.awt.Dialog.ModalityType;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.DefaultListModel;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import org.jdesktop.swingx.JXMapKit;
import org.jdesktop.swingx.JXMapKit.DefaultProviders;
import org.jdesktop.swingx.mapviewer.GeoPosition;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * mainframe.java
 *
 * Created on 27 Ιαν 2012, 3:16:41 πμ
 */
/**
 *
 * @author karolos
 */
public class mainframe extends javax.swing.JFrame {

    static DBManager db = new DBManager();//dhmioyrgia dbnanager antikeimenoy.gia perasma se alles klaseis

    /** Creates new form mainframe */
    public mainframe() throws SQLException  {
        rt=new reservationthread();
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        logopanel = new javax.swing.JPanel();
        cardpanel = new javax.swing.JPanel();
        loginpanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jPasswordField1 = new javax.swing.JPasswordField();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        adminpanel = new javax.swing.JPanel();
        butonpanel = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        maincardpanel = new javax.swing.JPanel();
        welcomepanel = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        userpanel = new javax.swing.JPanel();
        userbuttonpanel = new javax.swing.JPanel();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        usermaincardpanel = new javax.swing.JPanel();
        userwelcomepanel = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        searchpanel = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel8 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        restarea = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel10 = new javax.swing.JLabel();
        restpricerange = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Restaurant guide");

        logopanel.setBackground(new java.awt.Color(153, 153, 153));
        logopanel.setPreferredSize(new java.awt.Dimension(801, 100));

        javax.swing.GroupLayout logopanelLayout = new javax.swing.GroupLayout(logopanel);
        logopanel.setLayout(logopanelLayout);
        logopanelLayout.setHorizontalGroup(
            logopanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 620, Short.MAX_VALUE)
        );
        logopanelLayout.setVerticalGroup(
            logopanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        getContentPane().add(logopanel, java.awt.BorderLayout.PAGE_START);

        cardpanel.setPreferredSize(new java.awt.Dimension(801, 500));
        cardpanel.setLayout(new java.awt.CardLayout());

        loginpanel.setBackground(new java.awt.Color(255, 255, 255));
        loginpanel.setPreferredSize(new java.awt.Dimension(801, 650));
        loginpanel.setRequestFocusEnabled(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jButton1.setText("Σύνδεση");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setText("Σύνδεση στην εφαρμογή");

        jLabel3.setText("Όνομα Xρήστη:");

        jLabel2.setText("Κωδικός:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(jLabel1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)))))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        loginpanel.add(jPanel1);

        cardpanel.add(loginpanel, "loginpanel");

        adminpanel.setLayout(new java.awt.BorderLayout());

        butonpanel.setBackground(new java.awt.Color(255, 204, 153));

        jButton3.setText("Εισαγωγή Εστιατορίου");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Τροποποίηση Εστιατορίου");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Διαγραφή Εστιατορίου");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("Έξοδος");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout butonpanelLayout = new javax.swing.GroupLayout(butonpanel);
        butonpanel.setLayout(butonpanelLayout);
        butonpanelLayout.setHorizontalGroup(
            butonpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(butonpanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(butonpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(17, Short.MAX_VALUE))
        );
        butonpanelLayout.setVerticalGroup(
            butonpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(butonpanelLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jButton3)
                .addGap(37, 37, 37)
                .addComponent(jButton4)
                .addGap(40, 40, 40)
                .addComponent(jButton5)
                .addGap(35, 35, 35)
                .addComponent(jButton6)
                .addContainerGap(217, Short.MAX_VALUE))
        );

        adminpanel.add(butonpanel, java.awt.BorderLayout.LINE_START);

        maincardpanel.setLayout(new java.awt.CardLayout());

        welcomepanel.setBackground(new java.awt.Color(255, 255, 255));
        welcomepanel.setPreferredSize(new java.awt.Dimension(800, 500));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel4.setText("Συνδεθήκατε ως διαχειριστής!");

        javax.swing.GroupLayout welcomepanelLayout = new javax.swing.GroupLayout(welcomepanel);
        welcomepanel.setLayout(welcomepanelLayout);
        welcomepanelLayout.setHorizontalGroup(
            welcomepanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(welcomepanelLayout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(jLabel4)
                .addContainerGap(202, Short.MAX_VALUE))
        );
        welcomepanelLayout.setVerticalGroup(
            welcomepanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(welcomepanelLayout.createSequentialGroup()
                .addGap(59, 59, 59)
                .addComponent(jLabel4)
                .addContainerGap(368, Short.MAX_VALUE))
        );

        maincardpanel.add(welcomepanel, "card2");

        adminpanel.add(maincardpanel, java.awt.BorderLayout.CENTER);

        cardpanel.add(adminpanel, "adminpanel");

        userpanel.setLayout(new java.awt.BorderLayout());

        userbuttonpanel.setBackground(new java.awt.Color(255, 204, 153));

        jButton7.setText("Αναζήτηση Εστιατορίου");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("Έξοδος");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton13.setText("Εκκινηση Υπηρεσιας");
        jButton13.setActionCommand("Εκ");
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        jButton14.setText("Παυση Υπηρεσιας");
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout userbuttonpanelLayout = new javax.swing.GroupLayout(userbuttonpanel);
        userbuttonpanel.setLayout(userbuttonpanelLayout);
        userbuttonpanelLayout.setHorizontalGroup(
            userbuttonpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(userbuttonpanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(userbuttonpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton14, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(17, Short.MAX_VALUE))
        );
        userbuttonpanelLayout.setVerticalGroup(
            userbuttonpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(userbuttonpanelLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jButton7)
                .addGap(37, 37, 37)
                .addComponent(jButton13)
                .addGap(41, 41, 41)
                .addComponent(jButton14)
                .addGap(49, 49, 49)
                .addComponent(jButton8)
                .addContainerGap(202, Short.MAX_VALUE))
        );

        userpanel.add(userbuttonpanel, java.awt.BorderLayout.LINE_START);

        usermaincardpanel.setLayout(new java.awt.CardLayout());

        userwelcomepanel.setBackground(new java.awt.Color(255, 255, 255));

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel5.setText("Συνδεθήκατε ως χρήστης");

        javax.swing.GroupLayout userwelcomepanelLayout = new javax.swing.GroupLayout(userwelcomepanel);
        userwelcomepanel.setLayout(userwelcomepanelLayout);
        userwelcomepanelLayout.setHorizontalGroup(
            userwelcomepanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(userwelcomepanelLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel5)
                .addContainerGap(253, Short.MAX_VALUE))
        );
        userwelcomepanelLayout.setVerticalGroup(
            userwelcomepanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(userwelcomepanelLayout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addComponent(jLabel5)
                .addContainerGap(378, Short.MAX_VALUE))
        );

        usermaincardpanel.add(userwelcomepanel, "userwelcomecard");

        searchpanel.setLayout(new java.awt.BorderLayout());

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setMinimumSize(new java.awt.Dimension(173, 20));
        jPanel2.setPreferredSize(new java.awt.Dimension(35, 25));
        jPanel2.setRequestFocusEnabled(false);

        jLabel6.setFont(new java.awt.Font("Arial", 1, 14));
        jLabel6.setText("Αναζήτηση Εστιατορίου");
        jPanel2.add(jLabel6);

        searchpanel.add(jPanel2, java.awt.BorderLayout.NORTH);

        jPanel3.setMinimumSize(new java.awt.Dimension(150, 150));
        jPanel3.setPreferredSize(new java.awt.Dimension(450, 180));
        jPanel3.setLayout(new java.awt.BorderLayout());

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
        jPanel6.setMinimumSize(new java.awt.Dimension(100, 10));
        jPanel6.setPreferredSize(new java.awt.Dimension(450, 20));

        jLabel11.setFont(new java.awt.Font("Arial", 1, 14));
        jLabel11.setText("Αποτέλεσμα Αναζήτησης");
        jPanel6.add(jLabel11);

        jPanel3.add(jPanel6, java.awt.BorderLayout.NORTH);

        jPanel7.setBackground(new java.awt.Color(255, 255, 255));
        jPanel7.setPreferredSize(new java.awt.Dimension(450, 140));

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane2.setOpaque(false);
        jScrollPane2.setPreferredSize(new java.awt.Dimension(470, 140));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(jTable1);

        jPanel7.add(jScrollPane2);

        jPanel3.add(jPanel7, java.awt.BorderLayout.CENTER);

        jPanel8.setBackground(new java.awt.Color(255, 255, 255));
        jPanel8.setPreferredSize(new java.awt.Dimension(450, 35));
        jPanel8.setRequestFocusEnabled(false);
        jPanel8.setVerifyInputWhenFocusTarget(false);

        jPanel9.setBackground(new java.awt.Color(255, 255, 255));

        jButton10.setText("Προβολή");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jPanel9.add(jButton10);

        jButton11.setText("Αξιολόγηση");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        jPanel9.add(jButton11);

        jButton12.setText("Κράτηση");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });
        jPanel9.add(jButton12);

        jPanel8.add(jPanel9);

        jPanel3.add(jPanel8, java.awt.BorderLayout.SOUTH);

        searchpanel.add(jPanel3, java.awt.BorderLayout.PAGE_END);

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setPreferredSize(new java.awt.Dimension(400, 250));

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));

        jLabel7.setText("Όνομα εστιατορίου");

        jLabel8.setText("Περιοχή");

        jLabel9.setText("Κατηγορία");

        jScrollPane1.setViewportView(jList1);

        jLabel10.setText("Εύρος τιμών");

        jButton2.setText("Αναζήτηση");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton9.setText("Καθαρισμός φίλτρων");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel9)
                            .addComponent(jLabel8)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                            .addComponent(restpricerange, 0, 242, Short.MAX_VALUE)
                            .addComponent(restarea, 0, 242, Short.MAX_VALUE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton2)
                        .addGap(18, 18, 18)
                        .addComponent(jButton9)))
                .addContainerGap(75, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(restarea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel9)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(restpricerange, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton9))
                .addGap(8, 8, 8))
        );

        jPanel4.add(jPanel5);

        searchpanel.add(jPanel4, java.awt.BorderLayout.CENTER);

        usermaincardpanel.add(searchpanel, "usersearchcard");

        userpanel.add(usermaincardpanel, java.awt.BorderLayout.CENTER);

        cardpanel.add(userpanel, "userpanel");

        getContentPane().add(cardpanel, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents
//elegxos logon
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        CardLayout cl1 = (CardLayout) cardpanel.getLayout();
        int ad = db.checkadminlogin(jTextField1.getText(), jPasswordField1.getText());
        String us = db.checkuserlogin(jTextField1.getText(), jPasswordField1.getText());
       
        if (ad==1)
            cl1.show(cardpanel, "adminpanel");
        
        else if(us!=null){
            cl1.show(cardpanel, "userpanel");
            user=us;
            

        }
        else
        JOptionPane.showMessageDialog(butonpanel, "Το όνομα χρήστη ή ο κωδικός\n"
                    + "είναι εσφαλμένος.", "Σφάλμα Σύνδεσης", JOptionPane.ERROR_MESSAGE);
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        int i = JOptionPane.showConfirmDialog(null, "Είστε σίγουροι πως θέλετε \n να τερματίσετε την εφαρμογή?", "Επιβεβαίωση τερματισμού", JOptionPane.YES_NO_OPTION);
        if (i == JOptionPane.YES_OPTION) {
            System.exit(0);
        }

    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        jButton4.setEnabled(true);
        jButton5.setEnabled(true);
        jButton3.setEnabled(false);
        insertpanel ip = new insertpanel();
        maincardpanel.add("insertpanel", ip);
        CardLayout cl1 = (CardLayout) maincardpanel.getLayout();
        cl1.show(maincardpanel, "insertpanel");
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        jButton4.setEnabled(false);
        jButton5.setEnabled(true);
        jButton3.setEnabled(true);
        editpanel ep = new editpanel();

        maincardpanel.add("editpanel", ep);
        CardLayout cl1 = (CardLayout) maincardpanel.getLayout();
        cl1.show(maincardpanel, "editpanel");
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        try {
            jButton4.setEnabled(true);
            jButton5.setEnabled(false);
            jButton3.setEnabled(true);
            deletepanel dp = new deletepanel();
            maincardpanel.add("deletepanel", dp);
            CardLayout cl1 = (CardLayout) maincardpanel.getLayout();
            cl1.show(maincardpanel, "deletepanel");
        } catch (SQLException ex) {
            Logger.getLogger(mainframe.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    //pros8iki timon apo tin basi sta jcombo boxes kai jlist
    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        CardLayout cl1 = (CardLayout) usermaincardpanel.getLayout();
        cl1.show(usermaincardpanel, "usersearchcard");
        ArrayList<Integer> al = db.showAreas();//emfanisi perioxon se combobox
        restarea.addItem("");
        for (int i = 0; i < al.size(); i++) {
            restarea.addItem(al.get(i));

        }
        ArrayList<String> al2 = db.showPriceRange();//emfanisi eurous timon se combobox
        restpricerange.addItem("");
        for (int i = 0; i < al2.size(); i++) {
            restpricerange.addItem(al2.get(i));
        }

        ArrayList<String> al3 = db.showCategory();//emfanisi katigorion se jlist
        DefaultListModel info = new DefaultListModel();
        for (int i = 0; i < al3.size(); i++) {
            info.addElement(al3.get(i));
        }
        jList1.setModel(info);
    }//GEN-LAST:event_jButton7ActionPerformed

    //exodos apo tin efarmogi
    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        int i = JOptionPane.showConfirmDialog(null, "Είστε σίγουροι πως θέλετε \n "
                + "να τερματίσετε την εφαρμογή?",
                "Επιβεβαίωση τερματισμού", JOptionPane.YES_NO_OPTION);
        if (i == JOptionPane.YES_OPTION) {
            System.exit(0);
        }
    }//GEN-LAST:event_jButton8ActionPerformed

    //ka8arismos filtron
    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        jTextField2.setText("");
        restarea.setSelectedIndex(0);
        jList1.clearSelection();
        restpricerange.setSelectedIndex(0);

    }//GEN-LAST:event_jButton9ActionPerformed
//ANAZITISI ESTIATORIOY
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        String s1 = jTextField2.getText();
        String s2 = (String) restarea.getSelectedItem();
        String s3;
        String s4 = (String) restpricerange.getSelectedItem();
        if (jList1.getSelectedValue() == null) {
            s3 = "";
        } else {
            s3 = (String) jList1.getSelectedValue();
        }

        ResultSet rs = db.searchrestaurants(s1, s2, s3, s4);


        String a[];
        String header[] = {"Όνομα", "Διεύθυνση", "Περιοχή", "Τηλέφωνο", "Κατηγορία"};
        int count = header.length;

        mytablemodel model = new mytablemodel();


        for (int i = 0; i < count; i++) {
            model.addColumn(header[i]);
        }



        a = new String[count];

        try {

            while (rs.next()) {
                for (int i = 0; i < count; i++) {
                    a[i] = rs.getString(i + 1);
                }
                model.addRow(a);

            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Exception : " + e, "Error", JOptionPane.ERROR_MESSAGE);
        }
        jTable1.setModel(model);
        jTable1.revalidate();

    }//GEN-LAST:event_jButton2ActionPerformed
           //ypologismos mesou orou poiotitas,timon,exipiretisis estiatoriou
    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        JDialog test = new JDialog();
        viewrestaurant vr = new viewrestaurant();
        int quality = 0;
        int prices = 0;
        int servicetime = 0;
        float average = 0.0f;
        int count = 0;
        if (jTable1.getSelectedRow() != -1) {
            try {

                ResultSet rs = db.getrestaurantfromtable(
                        (String) jTable1.getValueAt(jTable1.getSelectedRow(), 0),
                        (String) jTable1.getValueAt(jTable1.getSelectedRow(), 1),
                        (String) jTable1.getValueAt(jTable1.getSelectedRow(), 2),
                        (String) jTable1.getValueAt(jTable1.getSelectedRow(), 3),
                        (String) jTable1.getValueAt(jTable1.getSelectedRow(), 4));
                try {
                    while (rs.next()) {
                        vr.getjLabel1().setText(rs.getString(1));
                        vr.getjLabel12().setText(rs.getString(2));
                        vr.getjLabel20().setText(rs.getString(3));
                        vr.getjLabel7().setText(rs.getString(4));
                        vr.getjLabel8().setText(rs.getString(8));
                        vr.getjLabel9().setText(rs.getString(6));
                        vr.getjLabel10().setText(rs.getString(5));
                        vr.getjTextArea1().setText(rs.getString(7));
                        if(rs.getString(9)!=null){
                        BufferedImage img = ImageIO.read(new File(rs.getString(9)));
                        Image imagenew=img.getScaledInstance(80, 60, WIDTH);
                        vr.getjXImagePanel1().setImage(imagenew);
                        }
                       
                    }
                } catch (IOException ex) {
                    Logger.getLogger(mainframe.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(mainframe.class.getName()).log(Level.SEVERE, null, ex);
                }

                ResultSet rs1 = db.getrestaurantsforeval(
                        (String) jTable1.getValueAt(jTable1.getSelectedRow(), 0),
                        (String) jTable1.getValueAt(jTable1.getSelectedRow(), 1),
                        (String) jTable1.getValueAt(jTable1.getSelectedRow(), 2),
                        (String) jTable1.getValueAt(jTable1.getSelectedRow(), 3),
                        (String) jTable1.getValueAt(jTable1.getSelectedRow(), 4));
                while (rs1.next()) {
                    count++;
                    quality += rs1.getInt(1);
                    prices += rs1.getInt(2);
                    servicetime += rs1.getInt(3);
                  }
                if (count>0){
                quality =quality/count;
                prices=prices/count;
                servicetime=servicetime/count;
                average = (quality + prices + servicetime) / 3;
                vr.getStarRater1().setRating(quality);
                vr.getStarRater2().setRating(prices);
                vr.getStarRater3().setRating(servicetime);
                vr.getStarRater4().setRating(average);
                }
                
            } catch (SQLException ex) {
                Logger.getLogger(mainframe.class.getName()).log(Level.SEVERE, null, ex);
            }

            

            //emfanisi xarth 
            JXMapKit mapViewer = new JXMapKit();
        mapViewer.setDefaultProvider(DefaultProviders.OpenStreetMaps);
        mapViewer.setDataProviderCreditShown(true);
        GeoPosition gp=restaurantguide.Utils.getGeoposition(vr.getjLabel20().getText());
        if (gp!=null){
        mapViewer.setZoom(2);
        mapViewer.setCenterPosition(gp);
        mapViewer.setAddressLocation(gp);
        vr.getjPanel4().add(mapViewer);
        }
        test.getContentPane().add(vr);
        test.setSize(475, 550);
        test.setResizable(false);
        test.setModalityType(ModalityType.APPLICATION_MODAL);
        test.setVisible(true);

    }//GEN-LAST:event_jButton10ActionPerformed
    }  //axiologisi estiatoriou
        private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
            JDialog test = new JDialog();
            String s1=(String) jTable1.getValueAt(jTable1.getSelectedRow(),0);
            String s2=(String) jTable1.getValueAt(jTable1.getSelectedRow(),1);
            String s3=(String) jTable1.getValueAt(jTable1.getSelectedRow(),2);
            String s4=(String) jTable1.getValueAt(jTable1.getSelectedRow(),3);
            String s5=(String) jTable1.getValueAt(jTable1.getSelectedRow(),4);
            
            int i=db.getrestid(s1, s2, s3, s4, s5);
            int check=db.checkeval(user, i);
            evaluaterest er=new evaluaterest();
            er.setRestname(s1);

            if (check==0){ //ελεγχος αν εχει ηδη αξιολογηθει απο τον ιδιο χρηστη
            er.getVathmos().setText("0");
            er.setFlag(false);
            
            }
              else{
            try {
                ResultSet rs = db.geteval(i, user);
                
                er.setFlag(true);
                rs.next();
                int quality=rs.getInt("quality");
                int prices=rs.getInt("prices");
                int servicetime=rs.getInt("servicetime");
                float avg=(quality+prices+servicetime)/3;
                er.getStarRater1().setRating(quality);
                er.getStarRater2().setRating(prices);
                er.getStarRater3().setRating(servicetime);
                er.getStarRater4().setRating(avg);
                er.getVathmos().setText(Float.toString(avg));
            } catch (SQLException ex) {
                Logger.getLogger(mainframe.class.getName()).log(Level.SEVERE, null, ex);
            }


              }
            er.setRestaurantid(i);
            er.setUserusername(user);
            test.getContentPane().add(er);
            test.setSize(416, 409);
            test.setResizable(false);
            test.setModalityType(ModalityType.APPLICATION_MODAL);
            test.setVisible(true);
        }//GEN-LAST:event_jButton11ActionPerformed
             //dimiourgia estiatorioy kai kratisi
        private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
         user us=new user(user);
         Restaurant rest = new Restaurant();
            try {
            String s1 = (String) jTable1.getValueAt(jTable1.getSelectedRow(),0);
            String s2 = (String) jTable1.getValueAt(jTable1.getSelectedRow(),1);
            String s3 = (String) jTable1.getValueAt(jTable1.getSelectedRow(),2);
            String s4 = (String) jTable1.getValueAt(jTable1.getSelectedRow(),3);
            String s5 = (String) jTable1.getValueAt(jTable1.getSelectedRow(),4);
            ResultSet rs = db.getrestaurantfromtable(s1, s2, s3, s4, s5);

            while (rs.next()) {
                rest.setName(rs.getString(1));
                rest.setAddress(rs.getString(2));
                rest.setAreaname(rs.getString(3));
                rest.setPhonenumber(rs.getString(4));
                rest.setCategoryname(rs.getString(5));
                rest.setInfo(rs.getString(6));
                rest.setDescription(rs.getString(7));
                rest.setRange(rs.getString(8));
                rest.setPhoto(rs.getString(9));

            }
        } catch (SQLException ex) {
            Logger.getLogger(mainframe.class.getName()).log(Level.SEVERE, null, ex);
        }
            //Reservation r=new Reservation(-1,us,rest);
            
            kratisiest ke=new kratisiest(rest,rt,user);
            
            JDialog dialog=new JDialog();
            
            dialog.getContentPane().add(ke);
            dialog.setSize(416, 409);
            dialog.setResizable(false);
            dialog.setVisible(true);
        }//GEN-LAST:event_jButton12ActionPerformed
              //ekkinisi thread
        private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
        
            rt.start();
            jButton13.setEnabled(false);
        }//GEN-LAST:event_jButton13ActionPerformed

        private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
            // TODO add your handling code here:
            jButton13.setEnabled(true);
            this.rt.setEnd(true);
        }//GEN-LAST:event_jButton14ActionPerformed

    /*
     * @param args the command line arguments
     */

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                mainframe mf;
                try {
                    mf = new mainframe();
                     mf.setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(mainframe.class.getName()).log(Level.SEVERE, null, ex);
                }
               



            }
        });


    }

    public static DBManager getDB() {  //perasma dbmanager se alles klaseis
        return db;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel adminpanel;
    private javax.swing.JPanel butonpanel;
    private javax.swing.JPanel cardpanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JPanel loginpanel;
    private javax.swing.JPanel logopanel;
    private javax.swing.JPanel maincardpanel;
    private javax.swing.JComboBox restarea;
    private javax.swing.JComboBox restpricerange;
    private javax.swing.JPanel searchpanel;
    private javax.swing.JPanel userbuttonpanel;
    private javax.swing.JPanel usermaincardpanel;
    private javax.swing.JPanel userpanel;
    private javax.swing.JPanel userwelcomepanel;
    private javax.swing.JPanel welcomepanel;
    // End of variables declaration//GEN-END:variables
    private String user;
    private reservationthread rt;
    //static me8odos gia emfanisi estiatorion sto jtable. tin me8odo ayti
    //tin kalei kai i klasi deletepanel gia antistoixi emfanisi ton estiatorion
    public static void showrestaurants(ResultSet rs, JTable jTable1) {
        try {
            rs = db.getrestaurants();
        } catch (SQLException ex) {
            Logger.getLogger(editpanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        String a[];
        String header[] = {"Όνομα", "Διεύθυνση", "Περιοχή", "Τηλέφωνο", "Κατηγορία"};
        int count = header.length;

        mytablemodel model = new mytablemodel();


        for (int i = 0; i < count; i++) {
            model.addColumn(header[i]);
        }



        a = new String[count];

        try {
            while (rs.next()) {
                for (int i = 0; i < count; i++) {
                    a[i] = rs.getString(i + 1);
                }
                model.addRow(a);

            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Exception : " + e, "Error", JOptionPane.ERROR_MESSAGE);
        }
        jTable1.setModel(model);



    }

   


}
